package com.oauth2.service;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisService {
	@Resource
	StringRedisTemplate stringRedisTemplate;
	
	
	public void set(String key,String value){
		stringRedisTemplate.opsForValue().set(key, value);
	}
	public String get(String key){
		return stringRedisTemplate.opsForValue().get(key);
	}
	
	public void hset(String key ,String field ,String value){
		stringRedisTemplate.opsForHash().put(key, field, value);
	}
	
	public String hget(String key ,String field){
		return (String) stringRedisTemplate.opsForHash().get(key, field);
	}
	public void expire(String key ,long time){//seconds
		stringRedisTemplate.expire(key, time, TimeUnit.SECONDS);
	}
	public void remove(String key ,String field){
		stringRedisTemplate.opsForHash().delete(key, field);
	}
	public void remove(String key){
		stringRedisTemplate.delete(key);
	}
	public long getExpire(String key){
		return stringRedisTemplate.getExpire(key);
	}
}
